package com.heima.controller;


import com.heima.pojo.dto.SkuQuery;
import com.heima.pojo.po.Sku;
import com.heima.pojo.vo.SkuVo;
import com.heima.pojo.vo.PageVo;
import com.heima.service.ISkuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Random;

/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author 存折
 * @since 2024-10-15
 */
@RestController
@RequestMapping
@Slf4j
public class SkuController {

    @Autowired
    private ISkuService iSkuService;

    @PostMapping("/api/vm-service/sku")
    public Boolean add(@RequestBody Sku sku) {
        log.info("接收到的参数{}", sku);
        Random random = new Random();
        long l = random.nextInt(100000);
        sku.setSkuId(l);
        iSkuService.save(sku);
        return true;
    }

    @GetMapping("/api/vm-service/sku/search")
    public PageVo<SkuVo> query(SkuQuery skuQuery) {
        return iSkuService.serch(skuQuery);
    }

    @PutMapping("/api/vm-service/sku/{skuId}")
    public  boolean update(@PathVariable String skuId,@RequestBody Sku sku){
        log.info("接收到的参数为{}",skuId);
        sku.setSkuId(Long.parseLong(skuId));
        iSkuService.updateById(sku);
        return true;
    }
}
